﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WeiTap.Validator.Result;

namespace WeiTap.Validator
{
    /// <summary>
    /// 验证器抽象接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IValidator<in T>:IValidator
    {
        /// <summary>
        /// 执行验证操作，并返回结果
        /// </summary>
        /// <param name="instance">待验证实例</param>
        /// <returns></returns>
        ValidationResult Validate(T instance);
        /// <summary>
        /// 执行验证操作，并返回结果
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        Task<ValidationResult> ValidateAsync(T instance, CancellationToken token = new CancellationToken());
        

    }
    public interface IValidator {
        /// <summary>
        /// 执行验证操作，并返回结果
        /// </summary>
        /// <param name="instance">待验证实例</param>
        /// <returns></returns>
        ValidationResult Validate(object instance);
        /// <summary>
        /// 执行验证操作，并返回结果
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        Task<ValidationResult> ValidateAsync(object instance, CancellationToken token = new CancellationToken());
        /// <summary>
        /// 执行验证操作，并返回结果
        /// </summary>
        /// <param name="context">待验证上下文</param>
        /// <returns></returns>
        ValidationResult Validate(ValidationContext context);
        ValidationResult ValidateAsync(ValidationContext context, CancellationToken token = new CancellationToken());
        /// <summary>
        /// 创建一个钩子来访问各种元数据属性
        /// </summary>
        /// <returns></returns>
        IValidatorDescriptor CreateDescriptor();
        bool CanValidateInstanceOfType(Type type);
        /// <summary>
        /// 设置验证器里面所有验证规则的验证模式
        /// </summary>
        CasecadeMode CasecadeMode { get; set; }
    }

    public enum CasecadeMode
    {
        Continue,
        StopOnFailure
    }
}
